package com.hustbaidu.hustmap;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class HustMapDBHelper extends SQLiteOpenHelper {
	
	private static final String DATABASE_NAME = "hust_map.db";
    private static final int DATABASE_VERSION = 1;
	
    public HustMapDBHelper(Context context){
    	super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
	
	public HustMapDBHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL("CREATE TABLE lecture (" +
				"_id INTEGER PRIMARY KEY, " + 
				"title TEXT, " + 
				"person TEXT, " +
				"start_time TIMESTAMP, " +
				"end_time TIMESTAMP, " +
				"type TEXT, " +
				"place INTEGER, " +
				"place_room TEXT, " +
				"introduce TEXT" +
				");");
		String insertMe = "INSERT INTO lecture (title, person, start_time, end_time, type, place, place_room, introduce) " +
                "VALUES ";
		db.execSQL(insertMe + "('创新人才，急速生活', '<美>Mary Peter', '2012-09-21 14:30:00', '2012-09-21 17:00:00', '人文', '0', '东九D310', '一个传统课程');");
		db.execSQL(insertMe + "('创新发展，急速生活', '<英>Mary Peter', '2012-09-22 19:00:00', '2012-09-22 21:00:00', '社科', '0', '西十二S310', '又是一个传统课程');");
		
		db.execSQL("CREATE TABLE comment (" +
				"_id INTEGER PRIMARY KEY, " + 
				"user_name TEXT, " + 
				"content TEXT, " +
				"time TIMESTAMP, " +
				"place INTEGER" +
				");");
		insertMe = "INSERT INTO comment (user_name, content, time, place) " + 
				"VALUES ";
		db.execSQL(insertMe + "('ddygg2010', '我把课本掉在D309了...', '2012-09-21 13:21:00', '0');");
		db.execSQL(insertMe + "('shenhanhe', '我捡到你的课本了...', '2012-09-21 15:20:00', '0');");
		db.execSQL(insertMe + "('hesfes222', '求捡课本啊，我的都丢好几个月了', '2012-09-22 10:34:00', '0');");
		
		db.execSQL("CREATE TABLE score (" +
				"_id INTEGER PRIMARY KEY, " + 
				"user_name TEXT, " + 
				"content TEXT, " +
				"time TIMESTAMP, " +
				"place INTEGER, " +
				"score INTEGER" +
				");");
		insertMe = "INSERT INTO score (user_name, content, time, place, score) " + 
				"VALUES ";
		db.execSQL(insertMe + "('ddygg2010', '味道不错', '2012-09-21 13:21:00', '0', '7');");
		db.execSQL(insertMe + "('shenhanhe', '糖醋里脊很给力', '2012-09-21 15:20:00', '0', '8');");
		db.execSQL(insertMe + "('hesfes222', '烧烤比较实惠', '2012-09-22 10:34:00', '0', '8');");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS lecture");
        onCreate(db);
	}

}
